﻿using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;


namespace calendar
{
    /// <summary>
    /// 输出2022年的日历
    /// </summary>
    internal class calendar
    {
        static void Main(string[] args)
        {
            int monthheight = 10;
            int columnwidth = 4 ;
            int monthwidth = 34;
            //1.putout month,“日一二三四五六”
            for (int month = 1; month<13;month++)
            {
                string string1 = "月";
                string string2 = "日  一  二  三  四  五  六";
                int y = ((month-1)/3)*monthheight, x =(month-1)%3*monthwidth +14 ;
                Console.SetCursorPosition(x, y);
                Console.Write(month);
                Console.WriteLine (string1);
                Console.SetCursorPosition(x - 14, y + 1);
                Console.Write(string2);
            }
            
            //set 1.1
            DateTime firstday = new DateTime(2022, 1, 1);

            //每次加一天，年号变了终止
            DateTime date = firstday;
            int x1 = 0, y1 = 0;
            do
            {
                //确定一号位置
                if (date.Day==1)
                {
                    y1 = (date.Month - 1) / 3 * monthheight+3; 
                    x1 = (date.Month-1)%3*monthwidth +(int)date.DayOfWeek * columnwidth;
                    Console.SetCursorPosition(x1, y1);
                    Console.Write(date.Day);
                }
                //确定其他日期的位置，当日期为周日时，需转行
                if(date.Day!=1)
                {
                    if(date.DayOfWeek==0)
                    {
                        x1 = (date.Month - 1) % 3 * monthwidth;
                        y1 = y1 + 1;
                        Console.SetCursorPosition(x1, y1);
                        Console.Write(date.Day);
                    }
                    else
                    {
                        x1 = x1 + 4;
                        Console.SetCursorPosition(x1, y1);
                        Console.Write(date.Day);
                    }
                }
                date = date.AddDays(1);
            } while (date.Year==2022);
        }
    }
}
